package com.hjxr.quota.define.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.hjxr.common.core.controller.BaseController;
import com.hjxr.quota.define.domain.vo.DimensionRootVo;
import com.hjxr.quota.define.service.IQuotaDimRelationDetailService;
import com.hjxr.quota.datasource.domain.QuotaDimension;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 预指标与维度（具体维度）关系表 前端控制器
 * </p>
 *
 * @author ma
 * @since 2020-10-16
 */
@RestController
@RequestMapping("/quotaDimRelationDetail")
@Api(tags = "预指标与具体维度接口")
public class QuotaDimRelationDetailController extends BaseController {
    @Autowired
    private IQuotaDimRelationDetailService quotaDimRelationDetailService;

    @GetMapping("{quotaId}")
    @ApiOperation(value = "根据指标id获取维度祖父节点")
    public R<List<DimensionRootVo>> getDimsByQuotaId(@PathVariable(value = "quotaId") Integer quotaId) {
        return success(quotaDimRelationDetailService.getDimsByQuotaId(quotaId));
    }
    @PostMapping("/beMixed")
    @ApiOperation(value = "查询指标公共维度 返回维度节点 每个节点中包含根节点值")
    public R<List<DimensionRootVo>> getBeMixedList(@RequestBody List<Integer> quotaIds){
        if(quotaIds==null||quotaIds.size()<=0){
            return failed("参数异常");
        }
        return success(quotaDimRelationDetailService.getBeMixedList(quotaIds));
    }

    @PostMapping("/beMixedRoot")
    @ApiOperation(value = "查询指标公共维度 只返回根节点")
    public R<List<DimensionRootVo>> getBeMixedRoot(@RequestBody List<Integer> quotaIds){
        if(quotaIds==null||quotaIds.size()<=0){
            return failed("参数异常");
        }
        return success(quotaDimRelationDetailService.getBeMixedRoot(quotaIds));
    }

    @PostMapping("/getBeMixedTree")
    @ApiOperation(value = "查询指标公共维度 返回所有节点")
    public R<List<QuotaDimension>> getBeMixedTree(@RequestBody List<Integer> quotaIds){
        if(quotaIds==null||quotaIds.size()<=0){
            return failed("参数异常");
        }
        return success(quotaDimRelationDetailService.getBeMixedTree(quotaIds));
    }

    @PostMapping("/commonDims")
    @ApiOperation(value = "计算多个指标共有具体维度", notes = "传入多个指标id返回共有具体维度id")
    private R<List<Integer>> commonDims(@RequestBody List<Integer> ids) {

        return success(quotaDimRelationDetailService.commonDims(ids));
    }

    /**
     * @param parms k：预指标id v:具体维度id列表
     * @return 该预指标的指标值
     */
    @PostMapping("/computeValue")
    @ApiOperation(value = "指标新生成指标计算指标值", notes = "传入一个预指标id多个具体维度id计算指标值")
    private R<Float> computeValue(@RequestBody Map<Integer, List<Integer>> parms) {

        return success(quotaDimRelationDetailService.computeValue(parms));
    }

    //根据具体维度id返回 一级维度id及

    @PostMapping("/queryUpperDim")
    @ApiOperation(value = "根据具体维度id查找其一级维度")
    private R<List<String>> queryUpperDim(@RequestBody List<Integer> dimIds){
        return success(quotaDimRelationDetailService.queryUpperDim(dimIds));

    }

}
